//
//  SAAboutUsVC.m
//  saasRetail
//
//  Created by 黄志刚 on 2021/7/1.
//

#import "SAAboutUsVC.h"
#import "SAUserExpireAPI.h"

@interface SAAboutUsVC ()<HTTPAPIDelegate>

@property (nonatomic, strong) UILabel *customerLab;
@property (nonatomic, strong) UILabel *weiXinLab;
@property (nonatomic, strong) UILabel *dateLab;
@property (nonatomic, strong) SAUserExpireAPI *userExpireAPI;

@end

@implementation SAAboutUsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma mark - HTTPAPIDelegate
- (void)fetchData:(id)data fromServerSuccessedWithAPI:(HTTPAPI *)api {
    if (self.userExpireAPI == api) {
        self.customerLab.text = data[@"data"][@"hotline"];
        self.weiXinLab.text = data[@"data"][@"wx"];
        self.dateLab.text = data[@"data"][@"dueDate"];
    }
}

- (void)fetchDataFromServerFailedWithError:(NSError *)error API:(HTTPAPI *)api {
    
}

-(void)clickedCopyBtn {
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = self.weiXinLab.text;
    [Prompt popPromptViewWithMsg:@"已复制到剪切板!" duration:3];
}

-(void)clickedIphoneBtn {
    NSMutableString *str= [[NSMutableString alloc] initWithFormat:@"telprompt://%@",self.customerLab.text];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str] options:[NSDictionary dictionary] completionHandler:nil];
}

-(void)initUI {
    [self setNavigationItemBackBBIAndTitle:@"关于我们"];
    self.view.backgroundColor = kLineColor;
    
    UIImageView *icon = [[UIImageView alloc] initWithFrame:SARectMake(150, StatusHeight + 26, 75, 75)];
    icon.image = [UIImage imageNamed:@"logo"];
    [self.view addSubview:icon];
    
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    UILabel *versionLab = [[UILabel alloc] initWithFrame:SARectMake(0, StatusHeight + 105, kBaseScreenWidth, 20)];
    versionLab.text = [NSString stringWithFormat:@"版本:%@",[infoDictionary objectForKey:@"CFBundleShortVersionString"]];
    versionLab.font = kFont(13);
    versionLab.textColor = kBlackColor;
    versionLab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:versionLab];
    
    UIView *whiteView = [[UIView alloc] initWithFrame:SARectMake(0, StatusHeight + 132, kBaseScreenWidth, 201)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:whiteView];
    
//    NSArray *arr = @[@"客服热线", @"客服微信", @"服务到期日"];
    NSArray *arr = @[@"客服热线", @"客服微信"];
    for (int i = 0; i < arr.count; i++) {
        UILabel *titleLab = [[UILabel alloc] initWithFrame:SARectMake(25, 41 * i, 90, 40)];
        titleLab.text = arr[i];
        titleLab.textColor = kBlackColor;
        titleLab.font = kFont(15);
        [whiteView addSubview:titleLab];
        
        UILabel *contentLab = [[UILabel alloc] initWithFrame:SARectMake(121, 41 * i, 200, 40)];
        contentLab.textColor = kBlackColor;
        contentLab.font = kFont(15);
        contentLab.textAlignment = NSTextAlignmentRight;
        [whiteView addSubview:contentLab];
        
        UIView *line = [[UIView alloc] initWithFrame:SARectMake(0, 40 + 41 * i, kBaseScreenWidth, 1)];
        line.backgroundColor = kLineColor;
        [whiteView addSubview:line];
        
        if (i == 0) {
            self.customerLab = contentLab;
            UIButton *iphoneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            iphoneBtn.frame = SARectMake(kBaseScreenWidth - 54, 0, 54, 40);
            [iphoneBtn setImage:[UIImage imageNamed:@"bule_iphone"] forState:UIControlStateNormal];
            [iphoneBtn addTarget:self action:@selector(clickedIphoneBtn) forControlEvents:UIControlEventTouchUpInside];
            [whiteView addSubview:iphoneBtn];
        }else if (i == 1) {
            self.weiXinLab = contentLab;
            titleLab.frame = SARectMake(25, 41, 90, 160);
            line.hidden = YES;
            UIImageView *wxImageV = [[UIImageView alloc] initWithFrame:SARectMake(kBaseScreenWidth - 165, 46, 150, 150)];
            wxImageV.image = [UIImage imageNamed:@"weixin_ydt"];
            [whiteView addSubview:wxImageV];
            
//            UIButton *copyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//            copyBtn.frame = SARectMake(kBaseScreenWidth - 54, 41, 54, 40);
//            [copyBtn setTitle:@"复制" forState:UIControlStateNormal];
//            [copyBtn setTitleColor:kBuleColor forState:UIControlStateNormal];
//            copyBtn.titleLabel.font = kFont(15);
//            [copyBtn addTarget:self action:@selector(clickedCopyBtn) forControlEvents:UIControlEventTouchUpInside];
//            [whiteView addSubview:copyBtn];
        }
    }
    [self.userExpireAPI sendRequestToServerWithActivityViewAndMask:POST];
    
    NSString *reView = kReView;
    if (reView && [reView isEqualToString:@"1"]) {
        whiteView.hidden = YES;
    }else {
        whiteView.hidden = NO;
    }
}

-(SAUserExpireAPI *)userExpireAPI {
    if (!_userExpireAPI) {
        _userExpireAPI = [SAUserExpireAPI apiWithDelegate:self];
    }
    return _userExpireAPI;
}

@end
